//var $j = jQuery.noConflict();
/* uncomment this block if there are some conflicts with other js library/framework */
(function ($) {

MyPage = {
    element: {
        btnSelectAllServices: null
		, btnReset: null
		, frmSearch: null
		, btnSearch: null
		, txtSearch: null
    },

    builder: {},

    application: {
		resetForm: function ( ){
			MyPage.element.frmSearch.find('input:checkbox[name="chkServiceType[]"]').attr('checked' , false ).attr('selected' , false );
			MyPage.element.frmSearch.each (function() {this.reset();});
			//MyPage.element.frmSearch.find('checkbox[name="radSearchType"]').attr('checked' , false ).attr('selected' , false );
		}
    },

    prepareElement: function () {
        this.element = {
            btnSelectAllServices: $("#btnSelectAllServices")
			, btnReset: $("#btnReset")
			, frmSearch: $("#frmSearch")
			, btnSearch: $("#btnSearch")
			, txtSearch: $("#txtSearch")
        };
    },

    prepareView: function () {
        this.element.btnSelectAllServices.button();
		this.element.btnReset.button();
		this.element.btnSearch.button();
		//this.element.txtSearch.hint();
    },

    eventBinding: function () {
        this.element.btnSelectAllServices.click(function () {
			MyPage.element.frmSearch.find('input:checkbox').attr('checked' , true ).attr('selected' , true );
        });
        this.element.btnReset.click(function () {
			MyPage.application.resetForm();
        });
        this.element.frmSearch.submit(function () {
			var isChecked = MyPage.element.frmSearch.find('input[name="chkServiceType[]"]:checked');
			if ( ! isChecked.length)
			{
				App.alert("Please select at least one Service" , "" )
				return false;
			}
        });
		this.element.frmSearch.delegate('.btnOrganisation', 'click', function () {
			var id = $(this).attr("itemprop");
			$("#hidOrganisationType").val(id);
			MyPage.element.frmSearch.submit();
        });

		this.element.btnReset.click(function () {
			MyPage.application.resetForm();
        });

		this.element.txtSearch.example(function() {
			return $(this).attr('title');
		}, {className: 'txtSearchHint'});


    },

    main: function () {
        this.prepareElement();
        this.prepareView();
        this.eventBinding();
    }
};

$(function () {
    MyPage.main();
});


$(document).ready(function() {
	//SD autosuggest
	var options_from = {
		script: function (dd_bus_bubble1) { 
			return 'http://www.streetdirectory.com/api/?mode=search&profile=sd_auto&country=sg&q='+dd_bus_bubble1+'&show_additional=1&output=js&start=0&limit=10&ctype=0&callback=set_data_search';
		} ,
		varname:"dd_bus_bubble1",
		json:true,
		shownoresults:false,
		timeout:5000,    
		minchars:1,
		maxresults:10,
		theme : 'min',
		left:0,
		maxwidth : '400px',                                                                         
		type_callback:'Direction',
		max_title_char_result : 30,
		callback: function (dd_bus_bubble1) { }
	};

	new bsn_main_search.AutoSuggest("txtSearch", options_from);
});


/* uncomment this block if there are some conflicts with other js library/framework */
})(jQuery);




